<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
</head>

<body>
    <div id="app">
        <input type="text" v-model.lazy="uname" />
        <div>{{tip}}</div>
    </div>
    <script src="../vue.js"></script>
    <script>
        var vm = new Vue({
            el: '#app',
            data: {
                uname: ' ',
                tip: ' ',
            },
            methods: {
                checkName: function(val) {
                    var that = this;
                    setTimeout(function() {
                        if (val === 'admin') {
                            that.tip = '用户名已存在，请重新输入';
                        } else {
                            that.tip = '用户名可用';
                        }
                    }, 500);
                },
            },
            watch: {
                uname: function(newName) {
                    this.checkName(newName);
                    this.tip = '正在验证中';
                },
            },
        });
    </script>
</body>

</html>